//
//  LGSmokeRecordCell.m
//  XieHeHeartDisease
//
//  Created by 1234 on 2024/1/31.
//

#import "LGDrinkRecordCell.h"

#define dateWidth    viewPix(87)
#define itemHeight   viewPix(32)
#define itemWidth    (Screen_W-viewPix(32)-dateWidth)/2.0

@interface LGDrinkRecordCell()
/**   */
@property (nonatomic , strong)UIView *baseView;
/**   */
@property (nonatomic , strong)UILabel *dateLabel;
/**   */
@property (nonatomic , strong)UILabel *itemLabel1;
/**   */
@property (nonatomic , strong)UILabel *itemLabel2;
/**   */
@property (nonatomic , strong)UIView *topLine;
/**   */
@property (nonatomic , strong)UIView *vertLine1;
/**   */
@property (nonatomic , strong)UIView *vertLine2;
/**   */
@property (nonatomic , strong)NSDictionary *colorDic;

@end

@implementation LGDrinkRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
        //1-今日未吸烟 、 2-今日已吸烟 、 3-未超过 、 4-超过
        self.colorDic = @{@"0":@"#AAAAAA",@"1":@"#282828",@"2":@"#EB5757",@"3":@"#282828",@"4":@"#EB5757"};
    }
    return  self;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    NSArray *tempArray = [LGNSString(dataDic[@"record_date"]) componentsSeparatedByString:@"-"];
    self.dateLabel.text = [NSString stringWithFormat:@"%@/%@",tempArray[1],tempArray[2]];
    self.itemLabel1.text = [NSString stringWithFormat:@"%@杯",dataDic[@"plan_num"]];
    self.itemLabel2.text = LGNSString(dataDic[@"state_name"]);
    self.itemLabel2.textColor = [UIColor colorWithString:self.colorDic[LGNSString(dataDic[@"state"])]];
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.clipsToBounds = YES;
    self.backgroundColor = [UIColor clearColor];
    self.contentView.backgroundColor = [UIColor clearColor];
    [self.contentView addSubview:self.baseView];
    [self.baseView addSubview:self.topLine];
    [self.baseView addSubview:self.dateLabel];
    [self.baseView addSubview:self.vertLine1];
    [self.baseView addSubview:self.itemLabel1];
    [self.baseView addSubview:self.vertLine2];
    [self.baseView addSubview:self.itemLabel2];
}
-(UIView *)baseView{
    if(!_baseView){
        _baseView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:10];
        _baseView.frame = CGRectMake(viewPix(16), -viewPix(10), Screen_W-viewPix(32), itemHeight+viewPix(20));
        _baseView.backgroundColor = [UIColor whiteColor];
    }
    return _baseView;
}

-(UIView *)topLine{
    if(!_topLine){
        _topLine = [[UIView alloc]initWithFrame:CGRectMake(0, viewPix(10), Screen_W-viewPix(32), 1)];
        _topLine.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _topLine;
}


-(UILabel *)dateLabel{
    if(!_dateLabel){
        _dateLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFont(12) textAlignment:NSTextAlignmentCenter lines:1];
        _dateLabel.frame = CGRectMake(0, kMaxY(self.topLine.frame), dateWidth, itemHeight);
    }
    return _dateLabel;
}


-(UILabel *)itemLabel1{
    if(!_itemLabel1){
        _itemLabel1 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _itemLabel1.frame = CGRectMake(kMaxX(self.vertLine1.frame), kMaxY(self.topLine.frame), itemWidth-1, itemHeight);
    }
    return _itemLabel1;
}

-(UILabel *)itemLabel2{
    if(!_itemLabel2){
        _itemLabel2 = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(15, UIFontWeightMedium) textAlignment:NSTextAlignmentCenter lines:1];
        _itemLabel2.frame = CGRectMake(kMaxX(self.vertLine2.frame), kMaxY(self.topLine.frame), itemWidth-1, itemHeight);
    }
    return _itemLabel2;
}

-(UIView *)vertLine1{
    if(!_vertLine1){
        _vertLine1 = [[UIView alloc]initWithFrame:CGRectMake(kMaxX(self.dateLabel.frame), 0, 1, viewPix(20)+itemHeight)];
        _vertLine1.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _vertLine1;
}

-(UIView *)vertLine2{
    if(!_vertLine2){
        _vertLine2 = [[UIView alloc]initWithFrame:CGRectMake(kMaxX(self.itemLabel1.frame), 0, 1, viewPix(20)+itemHeight)];
        _vertLine2.backgroundColor = [UIColor colorWithString:@"#F2F2F2"];
    }
    return _vertLine2;
}

@end
